import React, { Component } from "react";

function SonA() {
  const add = () => {
    this.setState({
      count: this.state.count + 1,
    });
  };
  return (
    <div>
      <span>SonA</span>
      <button onClick={add}>add</button>
    </div>
  );
}

function SonB(props) {
  return <div>SonB -- {props.count}</div>;
}

export default class App extends Component {
  state = {
    count: 0,
  };

  getCount = function(count) {
    return this.count;
  }
  render() {
    return (
      <div>
        <h2> 父组件</h2>
        <SonA count={this.state.count} getCount={this.getCount}/>
        <SonB count={this.state.count}/>
      </div>
    );
  }
}
